package dao

import (
	"gitee.com/zhengjianfeng/pay/models"
	"github.com/go-xorm/xorm"
)

type PayAccountDao struct {
	engine *xorm.Engine
}

func NewPayAccountDao(engine *xorm.Engine) *PayAccountDao {
	return &PayAccountDao{
		engine: engine,
	}
}

func (d *PayAccountDao) GetOne(username string) *models.PayAccount {
	var (
		data *models.PayAccount
		err  error
		ok   bool
	)
	data = &models.PayAccount{Username: username}
	if ok, err = d.engine.Get(data); ok && err == nil {
		return data
	} else {
		data.Id = 0
		return data
	}
}

func (d *PayAccountDao) GetSave(data *models.PayAccount) (err error) {

	_, err = d.engine.InsertOne(data)
	return
}
